package IOperation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
public class BorrowBook implements ioperation{
    @Override
    public void work(Booklist booklist) {
        //输入书名
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要借出的书籍：>");
        String bookname = scanner.nextLine();
        //通过数组查找是否存在
        int currentNum = booklist.getBookCount();
        int i = 0;
        for (; i < currentNum; i++) {
            Book book = booklist.getBooks(i);
            if(book.getBookname().equals(bookname)){
                break;
            }
        }

        //找不到
        if( i == currentNum) {
            System.out.println("找不到输入的书籍!");
            return;
        }

       //找到了
        Book book = booklist.getBooks(i);
        if(!book.isBorrowed()){
            System.out.println("此书未借出，可以选择借出！");
            Scanner scanner1 = new Scanner(System.in);
            System.out.println("请选择是否借出：1.借出   2.不借出");
            int choice = scanner.nextInt();
            if(choice == 1){
                book.isBorrowed = true;
                System.out.println( book.getBookname() + "成功借出，已登记！");
            }

        }

    }
}
